package cn.chenchao.eshop.goods.action;

import cn.chenchao.eshop.common.action.BaseAction;
import cn.chenchao.eshop.common.entity.Message;
import cn.chenchao.eshop.goods.entity.Goods;
import cn.chenchao.eshop.goods.service.IGoodService;
import cn.chenchao.eshop.goods.service.imp.GoodServiceImpl;
import util.JsonUtil;

import java.util.List;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/23 13:36
 * @Author : Chen Chao
 * @File : eshop.cn.chenchao.eshop.goods.action.GoodAction.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * /*封装商品操作消息
 */
public class GoodAction extends BaseAction {
    IGoodService service;
    public GoodAction() {
        service=new GoodServiceImpl();
    }


    public String showGoodsList(){
        /*1获取列表信息字符串*/
        List<Goods> goods = service.goodsList();
        if(goods==null){
            message.setMsgType(Message.FAILURE);
        }
        else {
            message.setMsgType(Message.SUCCESS);
            /*2把消息封装进message*/
            message.setObj(goods);
            System.out.println(iSysLog.normal("获取商品列表"));
        }
        /*3返回封装的消息*/
        return JsonUtil.entity2Json(message);
    }
}
